
//fontSize
(function(doc, win) {
	var docEl = doc.documentElement,
		resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
		recalc = function() {
			var clientWidth = docEl.clientWidth;
			if(!clientWidth) return;
			if(clientWidth <= 750) {
				docEl.style.fontSize = clientWidth / 10 + 'px';
			}
		};
	if(!doc.addEventListener) return;
	win.addEventListener(resizeEvt, recalc, false);
	doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

//service
var sselect;
var sselect2;
var sselect3;
var n;
function sersw(n){
	sselect = new Swiper('.ser-sw' + n + ' .swiper-container-select',{
	    scrollContainer:true,
	    mousewheelControl : true,
	    mode:'vertical',
	    scrollbar: {
	    	container :'.ser-sw' + n + ' .swiper-scrollbar',
	    	hide: false,
	    	draggable: true
	    }
	});
}
function sersw2(n){
	sselect2 = new Swiper('.ser-sw' + n + ' .swiper-container-select',{
	    scrollContainer:true,
	    mousewheelControl : true,
	    mode:'vertical',
	    scrollbar: {
	    	container :'.ser-sw' + n + ' .swiper-scrollbar',
	    	hide: false,
	    	draggable: true
	    }
	});
}
function sersw3(n){
	sselect3 = new Swiper('.ser-sw' + n + ' .swiper-container-select',{
	    scrollContainer:true,
	    mousewheelControl : true,
	    mode:'vertical',
	    scrollbar: {
	    	container :'.ser-sw' + n + ' .swiper-scrollbar',
	    	hide: false,
	    	draggable: true
	    }
	});
}

function  sselectdestory2(){
	sselect2.destroy(false);
	$('.ser-sw2').find(".swiper-scrollbar-drag").remove();
}
function  sselectdestory3(){
	sselect3.destroy(false);
	$('.ser-sw3').find(".swiper-scrollbar-drag").remove();
}

var sgaming;
var i;
function hswiper(i){
	sgaming = new Swiper('.gam-swi' + i + ' .swiper-container',{
		loop: false,
		autoplayDisableOnInteraction: false,
		autoplay: false,
		speed:500,
		slidesPerView:1,
		slidesPerGroup:1,
		calculateHeight : true,
		onTouchEnd: function(swiper){
			$('.gam-swi' + i + ' .swiper-container').find('p').find('i').html(sgaming.activeLoopIndex + 1);
		}
	});
	$('.gam-swi' + i + ' .gam-prev').click(function(){
		sgaming.swipePrev();
		$(this).siblings('p').find('i').html(sgaming.activeLoopIndex + 1);
	});
	$('.gam-swi' + i + ' .gam-next').click(function(){
		sgaming.swipeNext();
		$(this).siblings('p').find('i').html(sgaming.activeLoopIndex + 1);
	});
	$('.gam-swi' + i +' p b').html($('.gam-swi' + i).find('.swiper-slide').length);
}



//document
$(document).ready(function(){

	var ww = $(window).width();

	//nav
	$('.nav-btn').click(function() {
		$('.nav-main').slideToggle(400);
	});
	if(ww>1000){
		$('.nav-all').hover(
			function() {
				$(this).children('div').fadeIn(400)
			}, function() {
				$(this).children('div').fadeOut(400)
			}
		);
		$('.nav > li.nav-other').hover(
			function(){
				$(this).children('.nav-fir').fadeIn(400);
				var nfh = $(this).find('.nav-fir').height();
				$(this).find('.nav-sec,.nav-thi').css('min-height',nfh);
				// var nfh = $(this).find('.nav-fir').height();
				// var nsh = $(this).find('.nav-sec').height();
				// var nth = $(this).find('.nav-thi').height();
				// var max;
				// if(nfh>=nsh){
				// 	max = nfh;
				// }else{
				// 	max = nsh;
				// }
				// if(max<=nth){
				// 	max = nth;
				// }
				// $(this).find('.nav-fir,.nav-sec,.nav-thi').css('height',max);
			},function(){
				$(this).children('.nav-fir').fadeOut(400);
				$(this).find('.nav-fir > li').removeClass('nav-factive');
				$(this).find('.nav-sec > li').removeClass('nav-sactive');
			}
		);
		$('.nav-fir > li').hover(function(){
			$(this).addClass('nav-factive').siblings().removeClass('nav-factive');
			$(this).find('.nav-sec > li').removeClass('nav-sactive');
		});
		$('.nav-sec > li').hover(function(){
			$(this).addClass('nav-sactive').siblings().removeClass('nav-sactive');
		});
		$('.nav-thi > li').hover(function(){
			$(this).addClass('nav-tactive').siblings().removeClass('nav-tactive');
		});
		$('.nav-sec').siblings('a').addClass('nav-fbg');
		$('.nav-thi').siblings('a').addClass('nav-sbg');
		if(ww<=1200){
			$('.sea-submit').click(function(){
				$('.sea-info').fadeToggle();
			})
		}
	}else{
		/**- header -**/
		$('.nav-all > a').click(function() {
			$(this).parent().siblings('.nav-other').find('.nav-fir').slideUp(400);
			$(this).parent().siblings('.nav-other').find('.nav-sec').slideUp(400);
			$(this).parent().siblings('.nav-other').find('.nav-thi').slideUp(400);
			$(this).siblings('div').slideToggle(400);
		});
		$('.nav-all h2').click(function() {
			$(this).parents('li').find('.nav-sec').slideUp(400);
			$(this).siblings('.nav-sec').slideToggle(400);
		});
		$('.nav-all h3').click(function() {
			$(this).siblings('.nav-thi').slideToggle(400).parents('li').siblings().find('.nav-thi').slideUp(400);
		});

		$('.nav-other > a').click(function() {
			$(this).parent().siblings('.nav-other').find('.nav-fir').slideUp(400);
			$(this).parent().siblings().find('.nav-sec').slideUp(400);
			$(this).parent().siblings().find('.nav-thi').slideUp(400);
			$(this).siblings('.nav-fir').slideToggle(400);
			$(this).parent().siblings('.nav-all').find('.nav-fir').show();
			$(this).parent().siblings('.nav-all').children('div').slideUp(400);
		});
		$('.nav-other .nav-fir > li > a').click(function() {
			$(this).siblings('.nav-sec').slideToggle(400).parent().siblings().find('.nav-sec').slideUp(400);
		});
		$('.nav-other .nav-sec > li > a').click(function() {
			$(this).siblings('.nav-thi').slideToggle(400).parent().siblings().find('.nav-thi').slideUp(400);
		});

		/**- footer -**/
		$('.fo-nav h3').click(function() {
			$(this).siblings('div').slideToggle(400).parent().siblings().find('div').slideUp(400);
		});
	}

	//gotop
	$('.to-top').click(function() {
		$('html,body').animate({scrollTop:0}, 800);
	});
	

	//index-product
	$('.product').each(function(index, el) {
		var prolen = $(this).children('li').length;
		for(var i = 0; i<prolen; i++){
			if( i % 2 == 1 ){
				$(this).children('li').eq(i).addClass('pro-even');
			}
		}
	});


	/*=============== household-view.html ================*/
	$(window).scroll(function(){
		var stop = $(window).scrollTop();
		var hh = $('header').height();
		var pih = $('.pro-info').height();
		if(stop>=hh){
			$('.pro-info').addClass('pro-fixed');
			$('.pro-ftop').css({paddingTop:pih});
		}
		if(stop<hh){
			$('.pro-info').removeClass('pro-fixed');
			$('.pro-ftop').css({paddingTop:0});
		}
		if(stop>=200){
			$('.to-top').fadeIn(400);
		}
		if(stop<200){
			$('.to-top').fadeOut(400);
		}
	})
	$('.pro-menu a').click(function(event) {
		$(this).addClass('pro-active').siblings().removeClass('pro-active');
	});

	//banner-img
	var mySwiper2 = new Swiper('.banner-img',{
		loop: true,
		autoplayDisableOnInteraction: false,
		autoplay: 5000,
		speed:500,
		pagination: '.banner-img .pagination-banner',
		paginationClickable: true
	});
	$('.banner-img .banner-prev').click(function() {
		mySwiper2.swipePrev();
	});
	$('.banner-img .banner-next').click(function() {
		mySwiper2.swipeNext();
	});
	$('.banner-img .ban-stop').click(function() {
		mySwiper2.stopAutoplay();
		$('.banner-img .ban-start').fadeIn(300);
		$(this).fadeOut(300);
	});
	$('.banner-img .ban-start').click(function() {
		mySwiper2.startAutoplay();
		$('.banner-img .ban-stop').fadeIn(300);
		$(this).fadeOut(300);
	});


	//footer
	var swiperBar = new Swiper('.swiper-container-lang',{
	    scrollContainer:true,
	    mousewheelControl : true,
	    mode:'vertical',
	    scrollbar: {
	    	container :'.swiper-container-lang .swiper-scrollbar',
	    	hide: false,
	    	draggable: false
	    }
	});
	$('.lang-con h4').click(function() {
		if($(this).siblings('div').css('visibility')=='hidden'){
			$(this).siblings('div').css({
				visibility: 'visible'
			});
		}else{
			$(this).siblings('div').css({
				visibility: 'hidden'
			});
		}
	});
	$('.lang-con a').click(function() {
		// var dpic = $(this).attr('data-pic');
		// $('.fo-flag').attr('src',dpic);
		// $('.lang-con h4').html($(this).html());
		$('.lang-con > div').css({
			visibility:'hidden'
		});
	});


	//share
	window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"1","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
	
	if(ww>770){
		//toolbar
		$('.toolbar > div').hover(function() {
			$(this).children('div').fadeIn(400);
		}, function() {
			$(this).children('div').fadeOut(400);
		});
	}else{
		//toolbar
		$('.toolbar > div').click(function() {
			$(this).children('div').fadeToggle(400);
			$(this).siblings().children('div.poa').fadeOut(400);
		});
	}

	/*=============== household.html ================*/
	if(ww>750){
		var spurpose = new Swiper('.swiper-container-purpose',{
			loop: true,
			autoplayDisableOnInteraction: false,
			autoplay: false,
			speed:500,
			slidesPerView:3,
			slidesPerGroup:1,
			calculateHeight : true
		});

		$('.laptop > div').each(function(index, el) {
			var lapindex = $(this).index() + 1;
			var lpurpose = new Swiper('.lapsw' + lapindex + ' .swiper-container',{
				noSwiping : true,
				autoplayDisableOnInteraction: false,
				autoplay: false,
				speed:500,
				slidesPerView:4,
				slidesPerGroup:1,
				calculateHeight : true
			});
			$('.lapsw' + lapindex + ' .lap-prev').click(function(){
				lpurpose.swipePrev();
			});
			$('.lapsw' + lapindex + ' .lap-next').click(function(){
				lpurpose.swipeNext();
			});
		});
		$('.laptop > div').each(function(index, el) {
			var lslen = $(this).find('.swiper-wrapper').children('.swiper-slide').length;
			if(lslen<5){
				$(this).find('.swiper-container').find('.lap-arrow').hide();
			}
		});

		//makeyourmark
		var mwi = ($('.mark > .main').width()) * 0.25;
		$('.mark .feature li').css({'width':mwi});
		$('.mark .feature').each(function(index, el) {
			var mfl = $(this).children('li').length;
			$(this).css({'width': mfl*mwi})
		});

	}else{
		var spurpose = new Swiper('.swiper-container-purpose',{
			loop: true,
			autoplayDisableOnInteraction: false,
			autoplay: false,
			speed:500,
			slidesPerView:2,
			slidesPerGroup:1,
			calculateHeight : true
		});
		
		$('.laptop > div').each(function(index, el) {
			var lapindex = $(this).index() + 1;
			var lpurpose = new Swiper('.lapsw' + lapindex + ' .swiper-container',{
				noSwiping : false,
				autoplayDisableOnInteraction: false,
				autoplay: false,
				speed:500,
				slidesPerView:2,
				slidesPerGroup:1,
				calculateHeight : true
			});
			$('.lapsw' + lapindex + ' .lap-prev').click(function(){
				lpurpose.swipePrev();
			});
			$('.lapsw' + lapindex + ' .lap-next').click(function(){
				lpurpose.swipeNext();
			});
		});
		$('.laptop > div').each(function(index, el) {
			var lslen = $(this).find('.swiper-wrapper').children('.swiper-slide').length;
			if(lslen<3){
				$(this).find('.swiper-container').find('.lap-arrow').hide();
			}
		});

		//makeyourmark
		$('.mark .feature li').css({'width':'50%'});

		

	}
	$('.pur-prev').click(function(){
		spurpose.swipePrev();
	});
	$('.pur-next').click(function(){
		spurpose.swipeNext();
	});

	$('.laptop').each(function(index, el) {
		var laplen = $(this).children('div').length;
		for(var i = 0; i<laplen; i++){
			if(i % 2 == 1){
				$(this).children('div').eq(i).addClass('bgf5');
			}
		}
	});

	$('.swiper-container-purpose .swiper-wrapper').each(function(index, el) {
		if($(this).children('.swiper-slide').length == 0 ){
			$('.feature li').css({'padding-bottom':'3.3%'});
		}
	});


	/*=============== gaming.html ================*/
	hswiper(1);


	//tab点击
	$('.gam-menu li').click(function(){
		var gamindex = $(this).index();
		$(this).addClass('gam-active').siblings().removeClass('gam-active');
		$('.gam-con > div').eq(gamindex).show().siblings().hide();
		$('.gam-conmo > div').eq(gamindex).show().siblings().hide();
		sgaming.destroy(false);
		hswiper(gamindex + 1);
	})
	$('.com-menu li').click(function() {
		var comlen  = $(this).index();
		$(this).addClass('com-cactive').siblings().removeClass('com-cactive');
		$('.com-con > div').eq(comlen).show().siblings().hide();
	});


	//判断url上的#后的内容，关联到tab的标题到当前页
	var hash = window.location.hash;
	$('.com-menu a').each(function(index, el) {
		var chref = $(this).attr('href');
		if(chref == hash){
			$(this).parent('li').addClass('com-cactive').siblings().removeClass('com-cactive');
			$('.com-con > div').eq($('.com-cactive').index()).show().siblings().hide();
		}
	});
	$('.gam-menu a').each(function(index, el) {
		$(hash).parent('li').addClass('gam-active').siblings().removeClass('gam-active');
		$('.gam-con > div').eq($('.gam-active').index()).show().siblings().hide();
		$(hash).parent('li').click();
	});


	//当前页点击导航时，根据href获取的#后的内容，切换当前页tab内容
	$('.nav-sec a').click(function(){
		var myhref= $(this).attr('href');
		var newhref=myhref.substring(myhref.indexOf('#'), myhref.length);
		$('.com-menu a').each(function(index, el) {
			var chref = $(this).attr('href');
			if(chref == newhref){
				$(this).parent('li').addClass('com-cactive').siblings().removeClass('com-cactive');
				$('.com-con > div').eq($('.com-cactive').index()).show().siblings().hide();
			}
		});
		$('.bam-menu a').each(function(index, el) {
			var chref = $(this).attr('href');
			var ii = $(this).index();
			if(chref == newhref){
				$(this).parent('li').addClass('gam-cactive').siblings().removeClass('gam-cactive');
				$('.gam-con > div').eq($('.gam-cactive').index()).show().siblings().hide();
			}
		});
	});


	/*=============== solution.html ================*/
	$('.solution').each(function(index, el) {
		var soindex = $(this).children('li').length;
		for(var i=0; i<soindex; i++){
			if(i%2 == 1){
				$(this).children('li').eq(i).addClass('sol-even');
			}
		}
	});
	$('.sol-con').hover(function(){
		$(this).siblings('img').css({'transform':'scale(1.05)'})
	},function(){
		$(this).siblings('img').css({'transform':'scale(1)'})
	})

	/*=============== solution-aes.html ================*/
	$('.libg').each(function(index, el) {
		var lilen = $(this).children('li').length;
		for(var i=0; i<lilen; i++){
			if( i%2 == 1 ){
				$(this).children('li').eq(i).addClass('bgf5');
			}
		}
	});


	$('.login-user').parent().hover(function() {
		$('.user-con').fadeToggle(300);
	});
	$('.login,.nav-login').click(function(){
		$('.pop-login').fadeToggle(300);
	})
	$('.pop-layer,.pop-close').click(function(event) {
		$(this).parents('.popup').fadeOut(300);
	});
	$('.register').click(function() {
		$('.pop-register').fadeToggle(300);
	});
	$('.pop-pas').click(function() {
		$('.pop-login').hide();
		$('.pop-back').show();
	});
	$('.pop-reg').click(function() {
		$('.pop-login').hide();
		$('.pop-register').show();
	});
	
//	$('.m-address').click(function() {
//		$('.pop-address').fadeToggle(300);
//	});
//	$('.m-code').click(function() {
//		$('.pop-mpw').fadeToggle(300);
//	});
//	$('.m-nickname').click(function() {
//		$('.pop-nickname').fadeToggle(300);
//	});
//	$('.m-mailbox').click(function() {
//		$('.pop-mailbox').fadeToggle(300);
//	});
//	$('.m-phone').click(function() {
//		$('.pop-phone').fadeToggle(300);
//	});



	//找回密码

	$('.ser-snum li').each(function(index, el) {
		var sernum = $(this).attr('data-num');
		sersw(sernum);
	});
	$('.ser-select h4').click(function() {
		var svis = $(this).siblings('.ser-scon').css('visibility');
		if( svis == 'hidden' ){
			$(this).siblings('.ser-scon').css('visibility','visible');
		}else{
			$(this).siblings('.ser-scon').css('visibility','hidden');
		}
	});
	$('.ser-scon a').click(function() {
		$(this).parents('.ser-scon').siblings('h4').html($(this).html());
		$(this).parents('.ser-scon').css({'visibility':'hidden'});
	});
	
	$('.ser-select .ser-scon a').click(function(){
		var mes = $(this).html();
		$(this).parents('.ser-scon').siblings('input').val(mes);
	})
	


	//service-help
	$('.per-menu > li').click(function(){
		$(this).addClass('per-active').siblings().removeClass('per-active');
	})
	$('.pcshow .help-pro a').click(function(){
		$(this).parents('li').siblings('li').find('.help-pro a').removeClass('help-active');
		$(this).addClass('help-active').siblings().removeClass('help-active');
	})


	//service-support
	$('.sup-menu li').click(function() {
		$(this).addClass('sup-mactive').siblings().removeClass('sup-mactive');
		var smindex = $(this).index();
		$('.sup-pro > div').eq(smindex).show().siblings().hide();
	});

	$('.sea-type a').click(function() {
		$(this).toggleClass('sea-tactive').siblings().removeClass('sea-tactive');
	});


	$('.law-main h4').click(function() {
		$(this).siblings('.law-con').slideToggle(400).parents('li').siblings().find('.law-con').slideUp(400);
	});

	//buy.html
	$('.buy-menu li').click(function() {
		$(this).addClass('bimg-active').siblings('li').removeClass('bimg-active');
		var buyindex = $(this).index();
		$('.buy-con > div').eq(buyindex).show().siblings('div').hide();
	});

	//service-help.html
	$('.moshow .per-menu > li > a').click(function() {
		$(this).parent('li').siblings().find('.per-con').slideUp(400);
		$(this).siblings('.help-pro').find('.per-con').slideUp(400);
		$(this).siblings('.per-con').slideDown(400);
	});
	$('.moshow .help-pro a').click(function(){
		$(this).parent('li').siblings().find('.per-con').slideUp(400);
		$(this).parents('.help-pro').parents('li').siblings('li').find('.per-con').slideUp(400);
		$(this).parents('.help-pro').siblings('.per-con').slideUp(400);
		$(this).next('.per-con').slideDown(400);
		$(this).addClass('help-active').parent('li').siblings().find('a').removeClass('help-active');
	})



	



});


